import { BasicColumn, FormSchema } from '@apps/antd-admin/src/components/Table';
import { categoryList } from '@apps/ant-bus/src/views/business/goods/category/api';
import { render } from '@apps/antd-admin/src/hooks/render/renderUtils';
import { Api } from './api';

export const columns: BasicColumn[] = [
  {
    title: '合作企业',
    dataIndex: 'companyName',
    width: 150,
  },
  {
    title: '商品名称',
    dataIndex: 'goodsName',
    width: 150,
  },
  {
    title: '商品价格',
    dataIndex: 'goodsPrice',
    width: 120,
  },
  {
    title: '是否上架',
    dataIndex: 'goodsState',
    width: 80,
    renderApi: Api.setGoodsState,
    rowKey: 'companyGoodsId',
    customRender: render.renderSwitch,
  },
  {
    title: '过期日期',
    dataIndex: 'expireDate',
    width: 130,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 150,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'companyName',
    label: '企业名称',
    component: 'Input',
    colProps: { span: 5 },
  },
  {
    field: 'goodsName',
    label: '商品名称',
    component: 'Input',
    colProps: { span: 5 },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '公司Id',
    field: 'companyId',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '商品',
    field: 'goodsId',
    component: 'ApiModalSelect',
    required: true,
    componentProps: {
      multiple: '',
      selectConfig: {
        api: '/goods/page',
        rowKey: 'goodsId',
        labelKey: 'goodsName',
        modalTitle: '商品选择',
        searchForm: [
          {
            label: '商品分类',
            field: 'categoryId',
            component: 'ApiSelect',
            componentProps: {
              api: categoryList,
              labelField: 'categoryName',
              valueField: 'categoryId',
              immediate: true,
            },
          },
          {
            label: '商品名称',
            field: 'goodsName',
            component: 'Input',
          },
        ],
        columns: [
          {
            title: '商品名称',
            dataIndex: 'goodsName',
            width: 40,
            align: 'left',
          },
          {
            title: '商品图',
            dataIndex: 'coverImg',
            width: 50,
            align: 'center',
            customRender: render.renderImage,
          },
          {
            title: '市场价',
            dataIndex: 'goodsPrice',
            width: 50,
            align: 'center',
          },
        ],
      },
    },
  },
  {
    label: '商品价格',
    field: 'goodsPrice',
    component: 'Input',
    required: true,
  },
  {
    label: '上架状态',
    field: 'goodsState',
    component: 'Select',
    required: true,
    componentProps: {
      options: [
        { label: '未上架', value: 0 },
        { label: '上架', value: 1 },
      ],
    },
  },
  {
    label: '过期日期',
    field: 'expireDate',
    component: 'DatePicker',
    required: true,
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
];
